<?php

// +----------------------------------------------------------------------
// |  生成唯一单号
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace yicmf\tools;

class FlowSn
{
    /**
     * 亚秒精度
     */
    private static $precision = 3;
    /**
     * 生成的长度，不包含前缀及cid
     * 12位约为31年
     * 13位约为317年
     */
    private static $length = 12;
    
    public static function build($pre = 1,$cid = '')
    {
        // 开始时间戳
        $start_time_stamp = config('tools.flow_start_time_stamp');
        list($mic_sec, $sec) = explode(' ', microtime());
        $result = (time() - $start_time_stamp).str_pad(round($mic_sec * pow(10,self::$precision)),self::$precision,'0',STR_PAD_LEFT);
        return $pre.str_pad($result,self::$length,'0',STR_PAD_LEFT).$cid;
    }
}